# -*- coding:utf-8 *-
#导入os模块
import os
# md文档批量转word

dir = r'D:\void\mdTest'  #md文档路径

#调用os.walk读取文件名，os.path.splitext筛选后缀名为.md格式的文件，使用os.system在命令行中输入
def path(dir):
    for x, y, z in os.walk(dir):
        for name in z:
            a = os.path.splitext(name)[1]
            if a == '.md':
                file_path = x + '\\' + name
                print('pandoc ' + '"' + file_path + '"' + ' -o ' + x + '\\' + os.path.splitext(name)[0] + '.docx')
                os.system('pandoc ' + '"' + file_path + '"' + ' -o ' + '"' + x + '\\' + os.path.splitext(name)[
                    0] + '.docx' + '"')


if __name__ == '__main__':
    path(dir)